<template>
	<view class="">
		<view class=""><text class="device-icon-text baseicon-device"/>
			<view class="wifi-text"  :class="deviceObj.online?'baseicon-signal text-green':'baseicon-no-signal'">
			</view>
		</view>
		<view class="nav-title text-cut" style="width: 240rpx;">{{deviceObj.name}}</view>
		<view class="nav-name text-cut" style="width: 110rpx;">{{deviceObj.spaceName}}</view>
		<text class="baseicon-kaiguan" :class="deviceObj.online?'text-green':''" @tap="deviceSwitch"/>
		<text class="favorfill" :class="[deviceObj.collect?'baseicon-collect text-grey':'baseicon-no-collect']" @tap="deviceCollectChang"/>
		<text class="system-text baseicon-operate"  @tap="controlHandle"/>
		<text class="caozuo-text baseicon-system"  @tap="getDeviceInfo"/>
	</view>
</template>

<script>
	import { collectDevice } from "@/api/system/device"
	export default {
		name: 'device',
		emits:['renewData'],
		props: {
			deviceObj: {
				type: Object,
				default: {}
			},
			switch: {
				type: Boolean,
				default: true
			},
			control: {
				type: Boolean,
				default: true
			},
			system: {
				type: Boolean,
				default: true
			}
		},
		methods: {
			deviceSwitch(){
				this.deviceObj.isOpen=this.deviceObj.isOpen?false:true
				this.$modal.showToast(this.deviceObj.name+(this.deviceObj.isOpen?'开启':'关闭'))
			},
			deviceCollectChang(){
				this.deviceObj.collect=this.deviceObj.collect?false:true
				collectDevice(this.deviceObj).then(res => {
					this.$emit('renewData')
					this.$modal.showToast(this.deviceObj.collect?'添加常用':'取消常用')
				})
			},
			controlHandle(){
				this.$modal.showToast('打开'+this.deviceObj.name+'控制面板')
			},
			getDeviceInfo(){
				this.$modal.showToast('打开'+this.deviceObj.name+'设备详情')
			}
		}
	}
</script>

<style>
</style>
